<template>
	<view class="order-card">
		<view class="order-header">
			<text class="order-no">订单号：{{ order.order_sn }}</text>
			<text class="order-amount">
				{{order.status === 'paid'?"金额":"应付"}}：¥{{ order.pay_price }}
			</text>
		</view>
		<view class="order-time">{{ order.createtime }}</view>
		<view class="order-body">
			<image :src="order.image" class="order-img" mode="aspectFill" />
			<view class="order-info">
				<view class="order-title">{{ order.name }}</view>
				<view class="order-price">¥{{ order.pay_price }}</view>
				<view class="order-valid">有效期：365天</view>
			</view>
		</view>
		<view class="order-actions">
			<template v-if="order.pay_status === 1">
				<view class="btn-paid" disabled>已付款</view>
				<view class="btn-after" @tap="showQr = true">申请售后</view>
			</template>
			<template v-else>
				<view class="btn-cancel" @tap="$emit('cancel', order)">取消订单</view>
				<view class="btn-pay" @tap="$emit('pay', order)">立即支付</view>
			</template>
		</view>
		<view v-if="showQr" class="modal-mask" @tap.self="showQr = false">
			<view class="modal-content">
				<image class="qr-img" src="https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=weixin://dl/business/?ticket=example" mode="aspectFit" />
				<view class="modal-tip">可以扫描平台客服微信哦！</view>
				<view class="modal-close" @tap="showQr = false">
					<image :src="HTTP_IMG_URL() + '/static/images/close.png'" mode="aspectFill" class="contact-modal-close-img" />
				</view>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	name: 'OrderCard',
	props: {
		order: {
		  type: Object,
		  required: true
		}
	},
	data() {
		return {
			showQr: false
		}
	}
}
</script>

<style lang="scss" scoped>
.order-card {
  background: #fff;
  border-radius: 16rpx;
  margin: 24rpx 0;
  padding: 24rpx;
  box-shadow: 0 2rpx 8rpx #f0f1f5;
  position: relative;
  .order-header {
    display: flex;
    justify-content: space-between;
    font-size: 28rpx;
    color: #888;
    margin-bottom: 8rpx;
    .order-no {}
    .order-amount { color: #222; font-weight: bold; }
  }
  .order-time {
    font-size: 24rpx;
    color: #bbb;
    margin-bottom: 16rpx;
  }
  .order-body {
    display: flex;
    align-items: center;
    .order-img {
      width: 140rpx;
      height: 140rpx;
      border-radius: 12rpx;
      margin-right: 20rpx;
    }
    .order-info {
      flex: 1;
      .order-title {
        font-size: 32rpx;
        font-weight: bold;
        margin-bottom: 8rpx;
      }
      .order-price {
        color: #e53935;
        font-size: 32rpx;
        margin-bottom: 8rpx;
      }
      .order-valid {
        color: #888;
        font-size: 24rpx;
      }
    }
  }
  .order-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 16rpx;
    view {
	    margin-left: 16rpx;
	    font-size: 24rpx;
	    border-radius: 32rpx;
	    padding: 0 32rpx;
	    height: 50rpx;
	    line-height: 50rpx;
      &.btn-cancel {
        color: #888;
        background: #fff;
	    border: 1rpx solid #888;
      
      }
      &.btn-pay {
        color: #fff;
        background: #3478f6;
        border: 1rpx solid #3478f6;
      }
      &.btn-after {
        color: #888;
        background: #fff;
	    border: 1rpx solid #888;
      }
      &.btn-paid {
        color: #888;
        background: #fff;
	    border: 1rpx solid #888;
      }
    }
  }
  .modal-mask {
    position: fixed;
    left: 0; top: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.45);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    .modal-content {
      background: linear-gradient(135deg, #cbe7ff 0%, #fff 100%);
      border-radius: 32rpx;
      padding: 48rpx 32rpx 32rpx 32rpx;
      display: flex;
      flex-direction: column;
      align-items: center;
      min-width: 480rpx;
      min-height: 480rpx;
      position: relative;
	  justify-content: space-around;
      .qr-img {
        width: 300rpx;
        height: 300rpx;
        background: #fff;
        border-radius: 24rpx;
        margin-bottom: 32rpx;
        box-shadow: 0 4rpx 24rpx #b3d8ff44;
      }
      .modal-tip {
        color: #666;
        font-size: 28rpx;
        margin-bottom: 16rpx;
        text-align: center;
      }
      .modal-close {
        position: absolute;
        left: 50%;
	    bottom: -100rpx;
        transform: translateX(-50%);
        width: 64rpx;
        height: 64rpx;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
	    .contact-modal-close-img {
		      width: 60rpx;
		      height: 60rpx;
	    }
      }
    }
  }
}
</style> 